//
//  DirectionSelectionPopupViewController.m
//  Portable Traffic Signal Assistor
//
//  Created by Ding on 8/28/12.
//  Copyright (c) 2012 TTU. All rights reserved.
//

#import "DirectionSelectionPopupViewController.h"

@interface DirectionSelectionPopupViewController ()

@end

@implementation DirectionSelectionPopupViewController
@synthesize northButton;
@synthesize westButton;
@synthesize eastButton;
@synthesize southButton;
@synthesize centerButton;
@synthesize locationManager=_locationManager;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(id)init:(CLLocationManager *)locationManager
{
    self=[super init];
    if (self) {
        self.locationManager=locationManager;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [self setNorthButton:nil];
    [self setWestButton:nil];
    [self setEastButton:nil];
    [self setSouthButton:nil];
    [self setCenterButton:nil];
    [self setLocationManager:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc {
    [northButton release];
    [westButton release];
    [eastButton release];
    [southButton release];
    [centerButton release];
//    [_locationManager release];
    [super dealloc];
}
- (IBAction)clickCenterButton:(id)sender {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setBool:YES forKey:@"automaticDirection"];
    [self.locationManager startUpdatingLocation];
    [self.view removeFromSuperview];
    
}

- (IBAction)clickEastButton:(id)sender {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setBool:NO forKey:@"automaticDirection"];
    [userDefaults setDouble:90 forKey:@"direction"];
    [self.locationManager startUpdatingLocation];
    [self.view removeFromSuperview];
}

- (IBAction)clickWestButton:(id)sender {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setBool:NO forKey:@"automaticDirection"];
    [userDefaults setDouble:270 forKey:@"direction"];
    [self.locationManager startUpdatingLocation];
    [self.view removeFromSuperview];
}

- (IBAction)clickSouthButton:(id)sender {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setBool:NO forKey:@"automaticDirection"];
    [userDefaults setDouble:180 forKey:@"direction"];
    [self.locationManager startUpdatingLocation];
    [self.view removeFromSuperview];
}

- (IBAction)clickNorthButton:(id)sender {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setBool:NO forKey:@"automaticDirection"];
    [userDefaults setDouble:0 forKey:@"direction"];
    [self.locationManager startUpdatingLocation];
    [self.view removeFromSuperview];
}
@end
